<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>在线运行JS</title>
        <script type="text/javascript" language="javascript">
            var is_ie = document.all;
            //运行代码
            function runcode(obj){
                var winname = window.open('', "_blank", '');
                winname.document.open('text/html', 'replace');
                winname.opener = null;
                var script = document.createElement("script");
                //			script.type == 'text/javascript';
                //			script.language = 'javascript';
                //			script.text = obj.value;
                //			winname.document.body.insertBefore(script);
                
                var scripts = ' <script type="text/javascript" language="javascript">';
                scripts += obj.value;
                scripts += '</script';
                scripts += '>';
                winname.document.write(scripts);
                winname.document.close();
            }
            
            //复制代码
            function copycode(obj){
                if (is_ie && obj.style.display != 'none') {
                    var rng = document.body.createTextRange();
                    rng.moveToElementText(obj);
                    rng.scrollIntoView();
                    rng.select();
                    //or target=obj.createTextRange();
                    rng.execCommand("Copy");
                    rng.collapse(false);
                }
            }
            
            //另存代码
            function savecode(obj){
                var winname = window.open('', '_blank', 'top=10000');
                winname.document.open('text/html', 'replace');
                winname.document.write(obj.value);
                winname.document.execCommand('saveas', '', 'code.htm');
                winname.close();
            }
            
            //剪切代码
            function cutcode(obj){
                if (document.all) {
                    textRange = obj.createTextRange();
                    textRange.execCommand("cut");
                }
                else {
                    alert("IE only!");
                }
            }
            
            //粘贴代码
            function pastecode(obj){
                if (document.all) {
                    textRange = obj.createTextRange();
                    textRange.execCommand("paste");
                }
                else {
                    alert("IE only!");
                }
            }
            
            //清空代码
            function clearcode(){
                document.getElementById("runcode0").value = "";
            }
        </script>
    </head>
    <body>
        <textarea name="text" id="runcode0" cols="100" rows="20">
        </textarea>
        <br>
        <input type="button" value="运行代码" onClick="runcode(runcode0)" class="sumit">
	   <input type="button" value="保存代码" onClick="savecode(runcode0)" class="sumit">
	   <input type="button" value="复制代码" onClick="copycode(runcode0)" class="sumit">
	   <input type="button" value="剪切代码" onClick="cutcode(runcode0)" class="sumit">
	   <input type="button" value="粘贴代码" onClick="pastecode(runcode0)" class="sumit">
	   <input type="button" value="清空代码" onClick="clearcode()" class="sumit">
    </body>
</html>